package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/kafka/producer"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// CreateReqMessage 创建ReqMessage
// @Tags ReqMessage
// @Summary 创建ReqMessage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ReqMessage true "创建ReqMessage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /msg/createReqMessage [post]
func CreateReqMessage(c *gin.Context) {
	var msg model.ReqMessage
	_ = c.ShouldBindJSON(&msg)

	if err := producer.SendReq(&msg); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.Ok(c)
	}

}

// DeleteReqMessage 删除ReqMessage
// @Tags ReqMessage
// @Summary 删除ReqMessage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ReqMessage true "删除ReqMessage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /msg/deleteReqMessage [delete]
func DeleteReqMessage(c *gin.Context) {
	var msg model.ReqMessage
	_ = c.ShouldBindJSON(&msg)
	if err := service.DeleteReqMessage(msg); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteReqMessageByIds 批量删除ReqMessage
// @Tags ReqMessage
// @Summary 批量删除ReqMessage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ReqMessage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /msg/deleteReqMessageByIds [delete]
func DeleteReqMessageByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteReqMessageByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateReqMessage 更新ReqMessage
// @Tags ReqMessage
// @Summary 更新ReqMessage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ReqMessage true "更新ReqMessage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /msg/updateReqMessage [put]
func UpdateReqMessage(c *gin.Context) {
	var msg model.ReqMessage
	_ = c.ShouldBindJSON(&msg)
	if err := service.UpdateReqMessage(msg); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindReqMessage 用id查询ReqMessage
// @Tags ReqMessage
// @Summary 用id查询ReqMessage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ReqMessage true "用id查询ReqMessage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /msg/findReqMessage [get]
func FindReqMessage(c *gin.Context) {
	var msg model.ReqMessage
	_ = c.ShouldBindQuery(&msg)
	if err, remsg := service.GetReqMessage(msg.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"remsg": remsg}, c)
	}
}

// GetReqMessageList 分页获取ReqMessage列表
// @Tags ReqMessage
// @Summary 分页获取ReqMessage列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.ReqMessageSearch true "分页获取ReqMessage列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /msg/getReqMessageList [get]
func GetReqMessageList(c *gin.Context) {
	var pageInfo request.ReqMessageSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetReqMessageInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
